/**
 * 功能描述 卡片
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper")
	var Form = require("form");
	var Dialog = require("dialog");
	var store =require("store");
	var activeUser = store.get("user");	
	
    var instance = {
        initComponent: function (params,widget) {
        	var form=new Form({
       		 show:false,
        	 parentNode:".J-form",
       		 saveaction : function(){
       			 var data=form.getData();
       			 aw.saveOrUpdate("api/visitway/save",data,function(data){
       				 widget.get("grid").refresh();
					 widget.show([".J-grid"]).hide([".J-form"]);
					 widget.get("subnav").hide(["return"]).show(["add"]);
       			 });
       		 },
       		 cancelaction : function(){
       			     widget.show([".J-grid"]).hide([".J-form"]);
					 widget.get("subnav").hide(["return"]).show(["add"]);
					 widget.get("grid").refresh();
       		 },
	  			 model:{
					id:"visitway",
					items:[{
						name:"pkVisitWay",
						type:"hidden"
					},{
						name:"organization",
					    type:"hidden",
					    defaultValue:activeUser.organization.pkOrganization
					},{
						name:"version",
						type:"hidden",
						defaultValue:"0"
					},{
						name:"name",
						id:"name",
						label:"访问方式",
						validate:["required"]
					},{
						name:"description",
						id:"description",
						type:"textarea",
						label:"描述",
						height:100,
						exValidate: function(value){
							if(value.length>256){
								return "描述不能超过256个字";
							}else{
								return true;
							}
						}
					}]
				 }
       	 });
       	 widget.set("form",form);
        }
    };
    module.exports = instance;
});
